package xin.petstore.framework.web.validator;

import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class MoneyValidator
        implements ConstraintValidator<Money, Double> {
    private String moneyReg = "^\\d+(\\.\\d{1,2})?$";
    private Pattern moneyPattern = Pattern.compile(this.moneyReg);

    public void initialize(Money money) {
    }

    public boolean isValid(Double value, ConstraintValidatorContext arg1) {
        if (value == null)
            return true;
        return this.moneyPattern.matcher(value.toString()).matches();
    }
}
